// Input.js

"use strict";

import React from "react";
import PropTypes from "prop-types";
import {Image} from "react-native";
import {ImagePropTypes} from 'deprecated-react-native-prop-types';


export default class NetworkImage extends React.PureComponent {

  static propTypes = {
    ...ImagePropTypes,
    uri: PropTypes.string
  };

  static defaultProps = {
    ...Image.defaultProps
  };

  constructor(props) {
    super(props);
    this.state = {resizeMode: "center"};
  }


  render() {
    return <Image {...this.props}
                  source={{uri: this.props.uri}}
                  resizeMode={this.state.resizeMode}
                  defaultSource={require("./icon_image_loading.png")}
                  onLoad={() => {
                    this.setState({resizeMode: this.props.resizeMode});
                  }}
                  onError={() => {
                    this.setState({resizeMode: "center"});
                  }}
    />;
  }

}
